<%--
  Created by IntelliJ IDEA.
  User: gaosubo
  Date: 2020/9/9
  Time: 13:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>评分标准</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <%--<script type="text/javascript" src="/js/common/fileupload.js"></script>--%>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
    <script src="/lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.all.js?20200715.1" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/UEcontroller.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/formdesign/bootstrap/js/bootstrap.js?20200826" type="text/javascript" charset="utf-8"></script>
</head>
<style>
    .openFile input[type=file]{
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 18px;
        z-index: 99;
        opacity: 0;
    }
</style>
<body>
<div>
    <form class="layui-form" action="" style="margin: 10px;" lay-filter="ajaxforms">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">验证日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="date" readonly  id="date" lay-verify="date" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div style="height: 30px;line-height: 30px;text-align: center;background: #f2f2f2;margin-bottom: 10px">标志性成果</div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin: 0 auto">
                <textarea id="Dtextarea" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item"  style="margin-top:15px">
            <label class="layui-form-label" style="width: 100px;margin-left:-20px">上传附件</label>
            <div class="layui-input-inline" style="width: 300px;">
                <div id="fujians"></div>
                <div id="fileAll">
                </div>
                <a href="javascript:;" id="upfiles" class="openFile" style="float: left;margin-top:8px;position:relative">
                    <img src="../img/mg11.png" alt="">
                    <span>添加附件</span>
                    <input type="file" multiple id="fileupload" data-url="/upload?module=conclusion" name="file">
                </a>
                <span id="uptext"style="color: red;width: 250px;display: inherit;margin-left: 90px;margin-top: 8px">(上传附件不能超过50M)</span>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="planDel">
    <a class="layui-btn layui-btn-danger layui-btn-xs del2" lay-event="del2">删除</a>
</script>

<script>
    // 获取地址栏参数值
    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }

    var trId = getQueryString('trId');
    var type = getQueryString('type');
    var table,form,laydate,upload,layedit;
    var ue;

    $(function(){
        // ue = UE.getEditor('container',{elementPathEnabled : false});
        layui.use(['table', 'form', 'laydate','upload','layedit'], function () {
            table = layui.table,
                form = layui.form,
                laydate = layui.laydate,
                upload = layui.upload,
                layedit = layui.layedit;
            //日期
            laydate.render({
                elem: '#date'
                ,trigger: 'click'//呼出事件改成click
                ,type:'datetime'
                ,format: 'yyyy-MM-dd HH:mm:ss'
            });
            fileuploadFn('#fileupload', $('#fileAll'));
            //上传
            if(type==0 || type=="0"){
                $.ajax({
                    url: '/conclusion_review/getDataByTrId',
                    dataType: 'json',
                    type: 'post',
                    data:{
                        trId:trId,
                        trType:getQueryString('trType')
                    },
                    success:function (res) {
                        var obj =res.object
                        $('#date').val(obj.trTime)
                        $("#Dtextarea").text(obj.trOther);
                        var str = ''
                        if(obj.attachmentList == undefined){
                            str='';
                        }else if(obj.attachmentList.length>0){
                            str = '<div class="dech" deurl="' +obj.attachmentList[0].attUrl + '"><a href="/download?' + obj.attachmentList[0].attUrl + '" name="'+obj.attachmentList[0].attachName+'*" style="text-decoration:none;margin-left:5px;"><img src="/img/attachment_icon.png">' + obj.attachmentList[0].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"><input type="hidden" class="inHidden" value="' + obj.attachmentList[0].aid + '@' + obj.attachmentList[0].ym + '_' + obj.attachmentList[0].attachId +',"></div></div>'
                        }
                        $('#fileAll').html(str);
                        $('.deImgs').show();
                        layui.form.render()
                    }
                })
            }
            //查看
            if(type==1){
                $.ajax({
                    url: '/conclusion_review/getDataByTrId',
                    dataType: 'json',
                    type: 'post',
                    data:{
                        trId:trId,
                        trType:getQueryString('trType')
                    },
                    success:function (res) {
                        var obj =res.object
                        $('#date').val(obj.trTime)
                        $('#date').attr('disabled','disabled')
                        $("#Dtextarea").text(obj.trOther);
                        $("#Dtextarea").attr('disabled','disabled');
                        var str = ''
                        if(obj.attachmentList == undefined){
                            str='';
                        }else if(obj.attachmentList.length>0){
                            str = '<div class="dech" deurl="' +obj.attachmentList[0].attUrl + '"><a href="/download?' + obj.attachmentList[0].attUrl + '" name="'+obj.attachmentList[0].attachName+'*" style="text-decoration:none;margin-left:5px;"><img src="/img/attachment_icon.png">' + obj.attachmentList[0].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"><input type="hidden" class="inHidden" value="' + obj.attachmentList[0].aid + '@' + obj.attachmentList[0].ym + '_' + obj.attachmentList[0].attachId +',"></div></div>'
                        }
                        $('#fileAll').html(str);
                        $('#fileAll').css("margin-top","8px");
                        $('.deImgs').hide();
                        $("#upfiles").hide();
                        $("#uptext").hide();
                        layui.form.render()
                    }
                })
            }
        });
        //删除附件
        $(document).on('click', '.deImgs', function () {
            var _this = this;
            var attUrl = $(this).parents('.dech').attr('deUrl');
            layer.confirm('确定删除该附件吗？', function (index) {
                $.ajax({
                    type: 'get',
                    url: '/delete?' + attUrl,
                    dataType: 'json',
                    success: function (res) {
                        if (res.flag == true) {
                            layer.msg('删除成功', {icon: 6, time: 1000});
                            $(_this).parent().remove();
                        } else {
                            layer.msg('删除失败', {icon: 2, time: 1000});
                        }
                    }
                })
            });
        });
    });


    //成果列表保存
    function listSubmit() {
        var obj = {}
        //附件
        var attachmentId = '';
        var attachmentName = '';
        for (var i = 0; i < $('#fileAll .dech').length; i++) {
            attachmentId += $('#fileAll .dech').eq(i).find('input').val();
            attachmentName += $('#fileAll a').eq(i).attr('name');
        }
        obj.trId = trId
        obj.trTime = $('#date').val()
        obj.trOther= $("#Dtextarea").val();
        obj.attachmentId = attachmentId
        obj.attachmentName=attachmentName;
        $.ajax({
            url: '/conclusion_apply/uploadFile',
            dataType: 'json',
            type: 'post',
            data: obj,
            success: function (res) {
                if (res.msg == '修改成功') {
                    layer.msg("上传成功",{ icon:1},function(){
                        parent.closes();
                    });

                }
            }
        })
    }
    var timer=null;
    function fileuploadFn(formId,element) {
        // $('#uploadinputimg').fileupload({
        $(formId).fileupload({
            dataType:'json',
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress .bar').css(
                    'width',
                    progress + '%'
                );
                $('.barText').html(progress + '%');
                if(progress >= 100){  //判断滚动条到100%清除定时器
                    timer=setTimeout(function () {
                        $('#progress .bar').css(
                            'width',
                            0 + '%'
                        );
                        $('.barText').html('');
                    },2000);

                }
            },
            done: function (e, data) {
                if(data.result.obj!=undefined){
                    if(data.result.obj != ''){
                        var data = data.result.obj;
                        var str = '';
                        var str1 = '';
                        for (var i = 0; i < data.length; i++) {
                            var gs = data[i].attachName.split('.')[1];
                            // if(gs == 'jsp'||gs == 'css'||gs == 'js'||gs == 'html'||gs == 'java'||gs == 'php' ){ //后缀为这些的禁止上传
                            //     str += '';
                            //     layer.alert('jsp、css、js、html、java文件禁止上传!',{},function(){
                            //         layer.closeAll();
                            //     });
                            // }
                            /* else if(data[i].attachName.indexOf('+')!=-1){
                                     alert("你上传的"+data[i].attachName+"文件有特殊字符'+',文件名中不可存在特殊字符,请重新上传");

                             }*/
                            if(gs == 'pdf' || gs == 'PDF'){
                                var fileExtension=data[i].attachName.substring(data[i].attachName.lastIndexOf(".")+1,data[i].attachName.length);//截取附件文件后缀
                                var attName = encodeURI(data[i].attachName).replace(/\+/g, "%2b").replace(/\@/g,"%40").replace(/\#/g,"%23").replace(/\&/g,"%26").replace(/\//g,"%2F").replace(/\?/g,"%3F").replace(/\￥/g,"%ef%bf%a5").replace(/\$/g,"%24").replace(/\！/g,"%ef%bc%81").replace(/\（/g,"%ef%bc%88").replace(/\）/g,"%ef%bc%89").replace(/\…/g,"%e2%80%a6%e2%80%a6");
                                var fileExtensionName=attName.substring(0,attName.lastIndexOf("."));
                                var deUrl = data[i].attUrl.split('&ATTACHMENT_NAME=')[0]+"&ATTACHMENT_NAME="+fileExtensionName+"."+fileExtension+"&FILESIZE="+data[i].size;

                                str += '<div class="dech" deUrl="' + deUrl+ '"><a href="/download?'+encodeURI(deUrl)+'" NAME="' + data[i].attachName + '*" style="text-decoration:none;margin-left:5px;"><img src="/img/attachment_icon.png"/>' + data[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + data[i].aid + '@' + data[i].ym + '_' + data[i].attachId + ',"></div>';
                            } else {
                                str += '';
                                layer.alert('只能上传pdf文件!',{},function(){
                                    layer.closeAll();
                                });
                            }
                        }
                        // $('.Attachment td').eq(1).append(str);
                        console.log(element)
                        element.html(str);
                    }else{
                        layer.alert('添加附件大小不能为空!',{},function(){
                            layer.closeAll();
                        });
                    }
                }else {
                    if(data.result.datas != ''){
                        var data = data.result.datas;
                        var str = '';
                        var str1 = '';
                        for (var i = 0; i < data.length; i++) {
                            var gs = data[i].attachName.split('.')[1];
                            // if(gs == 'jsp'||gs == 'css'||gs == 'js'||gs == 'html'||gs == 'java'||gs == 'php' ){ //后缀为这些的禁止上传
                            //     str += '';
                            //     layer.alert('jsp、css、js、html、java文件禁止上传!',{},function(){
                            //         layer.closeAll();
                            //     });
                            // }
                            // /* else if(data[i].attachName.indexOf('+')!=-1){
                            //      alert("你上传的"+data[i].attachName+"文件有特殊字符'+',文件名中不可存在特殊字符,请重新上传");
                            //  }*/
                            // else{
                            //     var fileExtension=data[i].attachName.substring(data[i].attachName.lastIndexOf(".")+1,data[i].attachName.length);//截取附件文件后缀
                            //     var attName = encodeURI(data[i].attachName).replace(/\+/g, "%2b").replace(/\@/g,"%40").replace(/\#/g,"%23").replace(/\&/g,"%26").replace(/\//g,"%2F").replace(/\?/g,"%3F").replace(/\￥/g,"%ef%bf%a5").replace(/\$/g,"%24").replace(/\！/g,"%ef%bc%81").replace(/\（/g,"%ef%bc%88").replace(/\）/g,"%ef%bc%89").replace(/\…/g,"%e2%80%a6%e2%80%a6");
                            //     var fileExtensionName=attName.substring(0,attName.lastIndexOf("."));
                            //     var deUrl = data[i].attUrl.split('&ATTACHMENT_NAME=')[0]+"&ATTACHMENT_NAME="+fileExtensionName+"."+fileExtension+"&FILESIZE="+data[i].size;
                            //
                            //     str += '<div class="dech" deUrl="' + deUrl+ '"><a href="/download?'+encodeURI(deUrl)+'" NAME="' + data[i].attachName + '*" style="text-decoration:none;margin-left:5px;"><img  src="/img/attachment_icon.png"/>' + data[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + data[i].aid + '@' + data[i].ym + '_' + data[i].attachId + ',"></div>';
                            // }
                            if(gs == 'pdf' || gs == 'PDF'){
                                var fileExtension=data[i].attachName.substring(data[i].attachName.lastIndexOf(".")+1,data[i].attachName.length);//截取附件文件后缀
                                var attName = encodeURI(data[i].attachName).replace(/\+/g, "%2b").replace(/\@/g,"%40").replace(/\#/g,"%23").replace(/\&/g,"%26").replace(/\//g,"%2F").replace(/\?/g,"%3F").replace(/\￥/g,"%ef%bf%a5").replace(/\$/g,"%24").replace(/\！/g,"%ef%bc%81").replace(/\（/g,"%ef%bc%88").replace(/\）/g,"%ef%bc%89").replace(/\…/g,"%e2%80%a6%e2%80%a6");
                                var fileExtensionName=attName.substring(0,attName.lastIndexOf("."));
                                var deUrl = data[i].attUrl.split('&ATTACHMENT_NAME=')[0]+"&ATTACHMENT_NAME="+fileExtensionName+"."+fileExtension+"&FILESIZE="+data[i].size;

                                str += '<div class="dech" deUrl="' + deUrl+ '"><a href="/download?'+encodeURI(deUrl)+'" NAME="' + data[i].attachName + '*" style="text-decoration:none;margin-left:5px;"><img src="/img/attachment_icon.png"/>' + data[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + data[i].aid + '@' + data[i].ym + '_' + data[i].attachId + ',"></div>';
                            } else {
                                str += '';
                                layer.alert('只能上传pdf文件!',{},function(){
                                    layer.closeAll();
                                });
                            }
                        }
                        // $('.Attachment td').eq(1).append(str);
                        console.log(element)
                        element.append(str);
                    }else{
                        layer.alert('添加附件大小不能为空!',{},function(){
                            layer.closeAll();
                        });
                    }
                }

            }
        });
    }

</script>
</body>
</html>
